package com.example.gateway.config;

import org.springframework.cloud.gateway.route.Route;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.PredicateSpec;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.function.Function;

/**
 * @author zhaoren
 * @version 1.0
 * @description TODO
 * @date 2020/9/1 14:04
 **/
@Configuration
public class GateWayConfig {

    /**
     * 硬编码的方式配置路由
     * @return
     */
    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder routeLocatorBuilder){
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
        routes.route("path_route",r ->
             r.path("/china").uri("http://www.chinanews.com/china")).build();
        return routes.build();
    }

}
